package pkg{
    import mx.controls.Image;
	import mx.core.UIComponent;
	import mx.core.Application;
	import mx.events.FlexEvent;
	import mx.core.mx_internal;
	import flash.filters.*;
	import flash.display.Loader;
    import flash.display.Bitmap;
    import flash.events.Event;
    import flash.display.MovieClip;
	import flash.events.ProgressEvent;
	import flash.system.LoaderContext;
	import caurina.transitions.*;
	
    use namespace mx_internal;
    
    public class SmoothImageLoader extends Image {
        
        [Embed(source="../skin/imagepreloader.swf", symbol="Preloader")]
        private var FlashPreloaderSymbol:Class;
        
        private var clip:MovieClip = null;
        
        public function SmoothImageLoader():void {
            super(); 
            addEventListener(Event.OPEN,onOpen);
			addEventListener(Event.COMPLETE,onComplete);
        }
        
        /**
         * @private
        */
        override mx_internal function contentLoaderInfo_completeEventHandler(event:Event):void {
           	
            var smoothLoader:Loader = event.target.loader as Loader;
         //   var smoothImage:Bitmap = smoothLoader.content as Bitmap;
         //   smoothImage.smoothing = true;
            
            super.contentLoaderInfo_completeEventHandler(event);
        }
		
		protected function onComplete(event:Event):void
		{
			removeChild(clip);		
		//	event.target.filters = [getBitmapFilter()];
		//	updateDisplayList(event.target.width, event.target.height);
		//	onResize(event);
		//	addEventListener(Event.RESIZE, onResize);
		}	
		
		protected function onOpen(event:Event):void
		{
			clip = new FlashPreloaderSymbol();
			addChild(clip);
            clip.alpha = 0;
            Tweener.addTween(clip, {alpha:100, time:.1, delay:.05, transition:"linear"});
            clip.x = event.target.x + (event.target.width/2) - clip.width/2;
            clip.y = event.target.y + (event.target.height/2) - clip.height;
		}
	/*
   		private function getBitmapFilter():DropShadowFilter {
            var distance:Number = 0;
            var angle:Number = 90;
            var color:Number = 0x000000;
            var alpha:Number = 1;
            var blurX:Number = 12;
            var blurY:Number = 12;
            var strength:Number = 0.5;
            var quality:Number = BitmapFilterQuality.LOW;
            var inner:Boolean = false;
            var knockout:Boolean = false;

            return new DropShadowFilter(distance, angle, color, alpha, 
                blurX, blurY, strength, quality, inner, knockout);
        }
        
        protected function onResize(event:Event):void
        {
        	var myWidth:Number = event.target.content.width;
			var myHeight:Number = event.target.content.height;
			
			if ((myWidth > Application.application.width) || (myHeight > Application.application.height))
			{
				event.target.scaleContent = true;
			} else {
				event.target.scaleContent = false;
			}
        }
        */
    }
}